package o;

import com.google.gson.JsonSyntaxException;
import com.huawei.hwid.core.constants.HwAccountConstants;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

public final class auk implements ats {
    final boolean ˊ;
    private final atv ˏ;

    final class b<K, V> extends ato<Map<K, V>> {
        private final ato<V> ˊ;
        private final ato<K> ˋ;
        private final aua<? extends Map<K, V>> ˏ;
        final /* synthetic */ auk ॱ;

        public /* synthetic */ void ˎ(aux o_aux, Object obj) throws IOException {
            ˋ(o_aux, (Map) obj);
        }

        public /* synthetic */ Object ˏ(auy o_auy) throws IOException {
            return ˊ(o_auy);
        }

        public b(auk o_auk, atb o_atb, Type type, ato<K> o_ato_K, Type type2, ato<V> o_ato_V, aua<? extends Map<K, V>> o_aua__extends_java_util_Map_K__V) {
            this.ॱ = o_auk;
            this.ˋ = new auo(o_atb, o_ato_K, type);
            this.ˊ = new auo(o_atb, o_ato_V, type2);
            this.ˏ = o_aua__extends_java_util_Map_K__V;
        }

        public Map<K, V> ˊ(auy o_auy) throws IOException {
            auz ʻ = o_auy.ʻ();
            if (ʻ == auz.NULL) {
                o_auy.ॱॱ();
                return null;
            }
            Map<K, V> map = (Map) this.ˏ.ˋ();
            Object ˏ;
            if (ʻ == auz.BEGIN_ARRAY) {
                o_auy.ˊ();
                while (o_auy.ˋ()) {
                    o_auy.ˊ();
                    ˏ = this.ˋ.ˏ(o_auy);
                    if (map.put(ˏ, this.ˊ.ˏ(o_auy)) != null) {
                        throw new JsonSyntaxException("duplicate key: " + ˏ);
                    }
                    o_auy.ˎ();
                }
                o_auy.ˎ();
                return map;
            }
            o_auy.ॱ();
            while (o_auy.ˋ()) {
                att.ˎ.ˊ(o_auy);
                ˏ = this.ˋ.ˏ(o_auy);
                if (map.put(ˏ, this.ˊ.ˏ(o_auy)) != null) {
                    throw new JsonSyntaxException("duplicate key: " + ˏ);
                }
            }
            o_auy.ˏ();
            return map;
        }

        public void ˋ(aux o_aux, Map<K, V> map) throws IOException {
            int i = 0;
            if (map == null) {
                o_aux.ᐝ();
            } else if (this.ॱ.ˊ) {
                List arrayList = new ArrayList(map.size());
                List arrayList2 = new ArrayList(map.size());
                int i2 = 0;
                for (Entry entry : map.entrySet()) {
                    int i3;
                    ath ॱ = this.ˋ.ॱ(entry.getKey());
                    arrayList.add(ॱ);
                    arrayList2.add(entry.getValue());
                    if (ॱ.ᐝ() || ॱ.ʼ()) {
                        i3 = 1;
                    } else {
                        i3 = 0;
                    }
                    i2 = i3 | i2;
                }
                if (i2 != 0) {
                    o_aux.ˎ();
                    i2 = arrayList.size();
                    while (i < i2) {
                        o_aux.ˎ();
                        auc.ˎ((ath) arrayList.get(i), o_aux);
                        this.ˊ.ˎ(o_aux, arrayList2.get(i));
                        o_aux.ॱ();
                        i++;
                    }
                    o_aux.ॱ();
                    return;
                }
                o_aux.ˊ();
                i2 = arrayList.size();
                while (i < i2) {
                    o_aux.ॱ(ˏ((ath) arrayList.get(i)));
                    this.ˊ.ˎ(o_aux, arrayList2.get(i));
                    i++;
                }
                o_aux.ˏ();
            } else {
                o_aux.ˊ();
                for (Entry entry2 : map.entrySet()) {
                    o_aux.ॱ(String.valueOf(entry2.getKey()));
                    this.ˊ.ˎ(o_aux, entry2.getValue());
                }
                o_aux.ˏ();
            }
        }

        private String ˏ(ath o_ath) {
            if (o_ath.ʽ()) {
                atj ˏॱ = o_ath.ˏॱ();
                if (ˏॱ.ॱˋ()) {
                    return String.valueOf(ˏॱ.ॱ());
                }
                if (ˏॱ.ˊॱ()) {
                    return Boolean.toString(ˏॱ.ʻ());
                }
                if (ˏॱ.ॱˎ()) {
                    return ˏॱ.ˏ();
                }
                throw new AssertionError();
            } else if (o_ath.ॱॱ()) {
                return HwAccountConstants.NULL;
            } else {
                throw new AssertionError();
            }
        }
    }

    public auk(atv o_atv, boolean z) {
        this.ˏ = o_atv;
        this.ˊ = z;
    }

    public <T> ato<T> ˎ(atb o_atb, auv<T> o_auv_T) {
        Type ˏ = o_auv_T.ˏ();
        if (!Map.class.isAssignableFrom(o_auv_T.ˋ())) {
            return null;
        }
        Type[] ˋ = atp.ˋ(ˏ, atp.ˏ(ˏ));
        ato ˋ2 = ˋ(o_atb, ˋ[0]);
        ato ˏ2 = o_atb.ˏ(auv.ˋ(ˋ[1]));
        aua ˎ = this.ˏ.ˎ((auv) o_auv_T);
        return new b(this, o_atb, ˋ[0], ˋ2, ˋ[1], ˏ2, ˎ);
    }

    private ato<?> ˋ(atb o_atb, Type type) {
        if (type == Boolean.TYPE || type == Boolean.class) {
            return aup.ʼ;
        }
        return o_atb.ˏ(auv.ˋ(type));
    }
}
